<template>
    <div class="endBack2">
        <div class="txttitle">
            <span class="endtext" style="font-size:40px;">全国执业兽医资格考试</span>
            <span class="endtext">&nbsp;</span>
            <span class="endtext bg">
					<a style="display:block;width:220px;height:90px; float:left;margin-top:0px;margin-left:310px;cursor:pointer;font-size:50px;color:#000000;text-decoration:underline;font-weight:bold;"
                       @click="joinExam">点击进入</a>
				</span>
            <span class="endtext" style="margin-top:-140px;font-size:30px;">
					推荐使用IE浏览器
				</span>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import {examMixin} from "../mixins/mixin";
    import {getRequestQuery} from "@/utils/common";
    import {getQuestions} from "../api/exam";
    import {sha1} from "../utils/sha1";

    export default {
        mixins: [examMixin],
        data() {
            return {
                exam: []
            }
        },
        async created() {
            let queryData = getRequestQuery(), validateFlag = true;
            if (!queryData.no) {
                alert("缺少参数: no");
                validateFlag = false;
            }
            if (!queryData.item_no) {
                alert("缺少参数: item_no");
                validateFlag = false;
            }

            //  如果验证失败,则跳转到试卷选择页面
            if (!validateFlag) window.location.href = process.env.ERROR_LOCATION;

            //  获取考试试卷
            let result = await getQuestions(queryData);
            if(!result){
                alert("获取题目失败!");
                window.location.href = process.env.ERROR_LOCATION;
            }

            //  保存试卷题目
            this.setStore("questionsResult", result);

            //  得到考试的唯一识别key
            let examId = sha1(result.no + "_" + result.item_no);

            //  清空之前考试的状态
            let answerKey = "answer_" + examId;
            this.removeStore(answerKey);
            this.removeStore("joinTime");
            this.removeStore("mark_" + examId);
            this.removeStore("submit_answer_" + examId);
        },
        methods: {
            joinExam() {
                //  验证考试是否结束
                if (new Date() > new Date(this.exam.end_time)) {
                    alert("考试已结束!");
                    return;
                }
                //  进入考试录入界面
                this.$router.push("/enter");
            }
        }
    };


</script>

<style lang="stylus" rel="stylesheet/stylus">
    body {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
        background-color: #2d6dae;
    }

    .endBack2 {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 1024px;
        height: 768px;
        margin-left: -512px;
        margin-top: -384px;
        overflow: hidden;
        background: url(@/assets/static/img/back.jpg) no-repeat;
    }

    .txttitle {
        position: absolute;
        top: 190px;
        width: 100%;
        text-align: center;
    }

    .endtext {
        display: block;
        position: relative;
        color: #255dad;
        font-size: 32px;

        font-weight: bolder;
    }

    .bg {
        width: 850px;
        height: 350px;
        display: block;
        margin: 0 auto;
    }

    .buthome {
        position: absolute;
        top: 590px;
        width: 100%;
        text-align: center;
    }

    .inphome {
        width: 90px;
        background: url(@/assets/static/img/submit.gif) repeat-x;
        border: 1px solid #cc6600;
        color: #000000;
        font-size: 13px;
        cursor: pointer;
        border-radius: 0px;
        padding: 6px;
    }
</style>
